package com.intellagric.service.impl.module.loganalyse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.mapper.LogAnalyzeBusinessMapper;
import com.intellagric.pojo.LogAnalyzeBusiness;
import com.intellagric.pojo.LogAnalyzeBusinessExample;
import com.intellagric.service.module.loganalyse.LogAnalyzeBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: zhy
 * @Date: 2019/5/11
 * @Description: 日志分析业务线管理服务
 */
@Service
public class LogAnalyzeBusinessServiceImpl implements LogAnalyzeBusinessService {

    @Autowired
    private LogAnalyzeBusinessMapper logAnalyzeBusinessMapper;

    /**
    * 添加日志分析业务线信息
    * @param logAnalyzeBusiness
    * @return int
    */
    public ResponseMessage addLogAnalyzeBusiness(LogAnalyzeBusiness logAnalyzeBusiness) {
        if (logAnalyzeBusinessMapper.insertSelective(logAnalyzeBusiness) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除日志分析业务线信息
     * @param id
     * @return int
     */
    public ResponseMessage deleteLogAnalyzeBusiness(String id) {
        if (logAnalyzeBusinessMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改日志分析业务线信息
     * @param logAnalyzeBusiness
     * @return int
     */
    public ResponseMessage editLogAnalyzeBusiness(LogAnalyzeBusiness logAnalyzeBusiness) {
        if (logAnalyzeBusinessMapper.updateByPrimaryKeySelective(logAnalyzeBusiness) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 通过id查询日志分析业务线
     * @param id
     * @return LogAnalyzeBusiness
     */
    public LogAnalyzeBusiness queryLogAnalyzeBusinessById(String id) {
        return logAnalyzeBusinessMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询所有日志分析业务线信息
     * @return List<LogAnalyzeBusiness>
     */
    public LayuiDataGridResult queryLogAnalyzeBusinessList() {
        LogAnalyzeBusinessExample LogAnalyzeBusinessExample = new LogAnalyzeBusinessExample();
        LogAnalyzeBusinessExample.createCriteria().andIdIsNotNull();
        List<LogAnalyzeBusiness> logAnalyzeBusinessList = logAnalyzeBusinessMapper.selectByExample(LogAnalyzeBusinessExample);
        return LayuiDataGridResult.success().add(logAnalyzeBusinessList,logAnalyzeBusinessList.size());
    }

    /**
     * 分页查询所有日志分析业务线记录
     * @return List<LogAnalyzeBusiness>
     */
    public LayuiDataGridResult queryLogAnalyzeBusinessPage(int page, int rows) {
        PageHelper.startPage(page, rows);
        LogAnalyzeBusinessExample LogAnalyzeBusinessExample = new LogAnalyzeBusinessExample();
        LogAnalyzeBusinessExample.createCriteria().andIdIsNotNull();
        List<LogAnalyzeBusiness> logAnalyzeBusinessList = logAnalyzeBusinessMapper.selectByExample(LogAnalyzeBusinessExample);
        PageInfo<LogAnalyzeBusiness> pageInfo = new PageInfo<>(logAnalyzeBusinessList);
        return LayuiDataGridResult.success().add(logAnalyzeBusinessList,pageInfo.getTotal());
    }



}
